subroutine calculateSecondaryField(vertex2D,nVer2D,nInCat2D,params,igT,jgT,&
    ggT,ig,jg,ggu,ggl,di,f,l1,v1,v2,v3,v4,v5,ggl2,ggu2,di2,vertex3D,nVer3D,&
    nInCat3D,igT3D,jgT3D,ggT3D,log_txt,zLayers,xObjects,yObjects,zObjects,&
    numbersObjects,nLayers,nObjects,nXObjects,nYObjects,nZObjects,wk2d_dat,&
    wk3d_dat,sigmaLayers,sigmaObjects,areaObjects,areaType,layerType,nAreaObjects,&
    l13d,ig3D,jg3D,igEarth,jgEarth,vnRZ,vnXYZ,va,v0,wnRZ,wnXYZ,wa)
    common /dim2D/nodesCount2D,elemsCount2D,nodesBoundCount2D,nodesTermCount2D,m2D,mTerm2d,nodesNotTermCount2D
    common /dim3D/nodesCount3D,elemsCount3D,nodesBoundCount3D,edgesTermCount3D,edgesNotTermCount3D,&
    edgesCount3D,nodesTermCount3D,m3D,mTerm3d,nodesNotTermCount3D
    common /commonInfo/ eps2d,eps3d,eps3dNS,radiusRED,maxiter,typeTask,nt,nMaterials,calcWK,calcVP
    common /dimEarth/nodesNotTermEarth,mEarth
    integer elemsCount2D,edgesTermCount3D,edgesNotTermCount3D,edgesCount3D,elemsCount3D
    integer typeTask,calcWK,calcVP,log_txt,wk2d_dat,wk3d_dat,areaObjects,areaType
    real*8 vertex2D,vertex3D,params,ggT,ggu,ggl,di,f,v1,v2,v3,v4,v5,residual,ggl2,ggu2,&
    di2,eps2d,eps3d,eps3dNS,radiusRED,ggT3D,zLayers,xObjects,yObjects,zObjects,sigmaLayers,&
    sigmaObjects,vnRZ,vnXYZ,va,v0,wnRZ,wnXYZ,wa
    character*2 Ext
    dimension vertex2D(2,nodesCount2D),nVer2D(4,elemsCount2D),nInCat2D(elemsCount2D),&
    params(2,nMaterials)
    dimension igT(nodesTermCount2D+1),jgT(mTerm2d),ggT(mTerm2d),ig(nodesNotTermCount2D+1),&
    jg(m2d),ggu(m2d),ggl(m2d),di(nodesNotTermCount2D),f(nodesNotTermCount2D),l1(nodesBoundCount2D),&
    v1(nodesNotTermCount2D),v2(nodesNotTermCount2D),v3(nodesNotTermCount2D),v4(nodesNotTermCount2D),&
    v5(nodesNotTermCount2D),ggl2(m2d),ggu2(m2d),di2(nodesNotTermCount2D),wnRZ(nodesCount2D),&
    vertex3D(3,nodesCount3D),nVer3D(14,elemsCount3D),nInCat3D(elemsCount3D),wnXYZ(nodesCount3D),&
    igT3D(nodesTermCount3D+1),jgT3D(mTerm3d),ggT3D(mTerm3d),vnRZ(nodesCount2D),&
    vnXYZ(nodesCount3D),va(nodesCount3D),v0(nodesCount3D),zLayers(nLayers),&
    xObjects(nXObjects),yObjects(nYObjects),zObjects(nZObjects),numbersObjects(6,nObjects),&
    sigmaLayers(nLayers),sigmaObjects(nObjects),areaObjects(nAreaObjects),&
    areaType(2,nLayers+nObjects),ig3D(nodesNotTermCount3D+1),jg3D(m3d),l13d(nodesBoundCount3D),&
    igEarth(nodesNotTermEarth+1),jgEarth(mEarth),wa(nodesCount3D)

    do i=1,nLayers
        if(areaType(1,i).eq.2.and.layerType.eq.nObjects)then
            write(*,'(A,i,A)') 'VP: Area',i,' (2D-FullLayer)'
            write(log_txt,'(A,i,A)') 'VP: Area',i,' (2D-FullLayer)'
        elseif(areaType(1,i).eq.2)then
            write(*,'(A,i,A)') 'VP: Area',i,' (3D-FullLayer)'
            write(log_txt,'(A,i,A)') 'VP: Area',i,' (3D-FullLayer)'
        elseif(areaType(1,i).eq.3) then
            write(*,'(A,i,A)') 'VP: Area',i,' (3D-LayerWithoutObj)'
            write(log_txt,'(A,i,A)') 'VP: Area',i,' (3D-LayerWithoutObj)'
        endif

        call Wsigma_GS(vertex2D,nVer2D,nInCat2D,params,igT,jgT,ggT,ig,jg,ggu,ggl,&
        di,f,l1,v1,v2,v3,v4,v5,ggl2,ggu2,di2,vertex3D,nVer3D,nInCat3D,igT3D,&
        jgT3D,ggT3D,log_txt,i,zLayers,nLayers,vnRZ,wnRZ,wnXYZ)
        write(Ext,'(i2.2)') i
        open(wk2d_dat,file='.\calculations\vp\wk\w2d_'//Ext//'.dat',access='direct',recl=8,status='replace',mode='write')
        call writeToFileDouble(wk2d_dat,wnRZ,nodesCount2D)
        close(wk2d_dat)

        if(areaType(1,i).eq.2) then
            if(layerType.eq.nObjects) then
                write(Ext,'(i2.2)') i
                open(wk3d_dat,file='.\calculations\vp\wk\w3d_'//Ext//'.dat',access='direct',recl=8,status='replace',mode='write')
                call writeToFileDouble(wk3d_dat,wnXYZ,nodesCount3D)
                close(wk3d_dat)
            else
!                call WsigmaForFullLayer(params,ig3D,jg3D,ggu,ggl,di,f,l13d,v1,v2,v3,&
!                v4,v5,ggl2,ggu2,di2,vertex3D,nVer3D,nInCat3D,igT3D,jgT3D,&
!                ggT3D,igEarth,jgEarth,log_txt,zLayers,nLayers,i,va,wnXYZ,wa)
!                call vectorSumDouble(wa,wa,wnXYZ,nodesCount3D) 
!                write(Ext,'(i2.2)') i
!                open(wk3d_dat,file='.\calculations\vp\wk\w3d_'//Ext//'.dat',access='direct',recl=8,status='replace',mode='write')
!                call writeToFileDouble(wk3d_dat,wa,nodesCount3D)
!                close(wk3d_dat)
            endif
        elseif(areaType(1,i).eq.3) then
            call WsigmaLayerWithoutObj(params,ig3D,jg3D,ggu,ggl,di,f,l13d,v1,v2,v3,&
            v4,v5,ggl2,ggu2,di2,vertex3D,nVer3D,nInCat3D,igT3D,jgT3D,ggT3D,&
            igEarth,jgEarth,log_txt,zLayers,nLayers,areaObjects,areaType,&
            nAreaObjects,xObjects,yObjects,zObjects,numbersObjects,&
            nXObjects,nYObjects,nZObjects,nObjects,i,vnXYZ,va,wnXYZ,wa)
            call vectorSumDouble(wa,wa,wnXYZ,nodesCount3D) 
            write(Ext,'(i2.2)') i
            open(wk3d_dat,file='.\calculations\vp\wk\w3d_'//Ext//'.dat',access='direct',recl=8,status='replace',mode='write')
            call writeToFileDouble(wk3d_dat,wa,nodesCount3D)
            close(wk3d_dat)
        endif
    enddo

    do i=1,nObjects
        if(areaType(1,nLayers+i).eq.1) then
            write(*,'(A,i,A)') 'VP: Area',nLayers+i,' (Object)'
            write(log_txt,'(A,i,A)') 'VP: Area',nLayers+i,' (Object)'
            call WForObject(params,ig3D,jg3D,ggu,ggl,di,f,l13d,v1,v2,v3,&
            v4,v5,ggl2,ggu2,di2,vertex3D,nVer3D,nInCat3D,igT3D,jgT3D,&
            ggT3D,igEarth,jgEarth,log_txt,zLayers,nLayers,areaObjects,areaType,&
            nAreaObjects,xObjects,yObjects,zObjects,numbersObjects,&
            nXObjects,nYObjects,nZObjects,nObjects,i,v0,wa)

            write(Ext,'(i2.2)') nLayers+i
            open(wk3d_dat,file='.\calculations\vp\wk\w3d_'//Ext//'.dat',access='direct',recl=8,status='replace',mode='write')
            call writeToFileDouble(wk3d_dat,wa,nodesCount3D)
            close(wk3d_dat)
        endif
    enddo
end
!*************************************************************************
integer function delta(numArea,z1,z2,zLayers,nLayers)
    dimension zLayers(nLayers)
    real*8 z1,z2,zLayers
    if(numArea.eq.1)then
        if(z1.le.zLayers(numArea).and.z2.le.zLayers(numArea))then
            delta=1
        else
            delta=0
        endif
    elseif(z1.ge.zLayers(numArea-1).and.z2.le.zLayers(numArea)) then
        delta=1
    else
        delta=0
    endif
end
!*************************************************************************
integer function lidDelta(listObject,nList,x1,x2,y1,y2,z1,z2,zLayers,&
    nLayers,numArea,xObjects,yObjects,zObjects,numbersObjects,nXObjects,&
    nYObjects,nZObjects,nObjects)
    dimension listObject(nList),zLayers(nLayers),xObjects(nXObjects),&
    yObjects(nYObjects),zObjects(nZObjects),numbersObjects(6,nObjects)
    real*8 x1,x2,y1,y2,z1,z2,zLayers,xObjects,yObjects,zObjects

    lidDelta=0
    i=1
    do while(i.le.nList.and.lidDelta.eq.0)
        k=listObject(i)
        if(x1.ge.xObjects(numbersObjects(1,k)).and.x2.le.xObjects(numbersObjects(2,k)).and.&
           y1.ge.yObjects(numbersObjects(3,k)).and.y2.le.yObjects(numbersObjects(4,k)).and.&
           z1.ge.zObjects(numbersObjects(5,k)).and.z2.le.zObjects(numbersObjects(6,k)))then
            lidDelta=1
        endif
        i=i+1
    enddo
end
!*************************************************************************
integer function deltaObject(numArea,x1,x2,y1,y2,z1,z2,&
    xObjects,yObjects,zObjects,numbersObjects,&
    nXObjects,nYObjects,nZObjects,nObjects)
    dimension xObjects(nXObjects),yObjects(nYObjects),zObjects(nZObjects),&
    numbersObjects(6,nObjects)
    real*8 x1,x2,y1,y2,z1,z2,xObjects,yObjects,zObjects

    if(x1.ge.xObjects(numbersObjects(1,numArea)).and.&
       x2.le.xObjects(numbersObjects(2,numArea)).and.&
       y1.ge.yObjects(numbersObjects(3,numArea)).and.&
       y2.le.yObjects(numbersObjects(4,numArea)).and.&
       z1.ge.zObjects(numbersObjects(5,numArea)).and.&
       z2.le.zObjects(numbersObjects(6,numArea)))then
        deltaObject=1
    else
        deltaObject=0
    endif
end
!*************************************************************************
!*************************************************************************
!*************************************************************************